package cn.wolfcode.vo;

import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

public class JSONResultVo implements Serializable {

    @Setter
    @Getter
    private Boolean success = true;
    @Getter
    private String errorMsg;
    @Setter
    @Getter
    private Object result;

    public void setErrorMsg(String msg) {
        this.errorMsg = msg;
        this.success = false;
    }

    /**
     * 定义instance方法,方便传参给controller
     *
     * @return
     */
    public static JSONResultVo instance() {
        return new JSONResultVo();
    }

    /**
     * 如果后台抛了异常,下面的instance方法就会带上错误信息传值
     *
     * @param errorMsg
     * @return
     */
    public static JSONResultVo instance(String errorMsg) {
        JSONResultVo jsonResult = new JSONResultVo();
        jsonResult.setErrorMsg(errorMsg);
        return jsonResult;
    }

}
